package com.zeei.ems.meet.controller;

import com.github.pagehelper.PageInfo;
import com.zeei.ems.base.constant.GlobalConstant;
import com.zeei.ems.base.controller.BasicController;
import com.zeei.ems.base.page.PageParamVO;
import com.zeei.ems.base.result.ResultBasicVO;
import com.zeei.ems.base.result.ResultDataVO;
import com.zeei.ems.base.result.ResultRowsVO;
import com.zeei.ems.meet.model.MeetingRecordVO;
import com.zeei.ems.meet.model.dto.MemberDto;
import com.zeei.ems.meet.model.vo.MeetingRecordParam;
import com.zeei.ems.meet.service.MeetingRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "音视频会议接口")
@RestController
@RequestMapping("/ems/meeting")
public class MeetingRecordController extends BasicController {
    @Autowired
    MeetingRecordService meetingService;

    @ApiOperation(value = "分页查询会议列表")
    @PostMapping("/page/list")
    public ResultRowsVO<MeetingRecordVO> listMeetingContactPage(PageParamVO page,
                                                             @RequestBody MeetingRecordParam meetingRecord){
        PageInfo<MeetingRecordVO> meetingRecordPageInfo = meetingService.listMeetingRecord(page, meetingRecord);
        return this.createResultRowsVO(meetingRecordPageInfo, GlobalConstant.SUCCEED, "");
    }

    @ApiOperation(value = "查询会议列表")
    @PostMapping("/list")
    public ResultRowsVO<MeetingRecordVO> listMeetingContact(@RequestBody MeetingRecordParam meetingRecord){
        meetingRecord.setMeetingStatus(0);
        List<MeetingRecordVO> meetingRecordList = meetingService.listMeetingRecord(meetingRecord);
        return this.createResultRowsVO(meetingRecordList, GlobalConstant.SUCCEED, meetingRecordList.size());
    }

    @ApiOperation(value = "获取单个会议信息")
    @PostMapping("/get")
    public ResultDataVO<MeetingRecordVO> getMeetingContact(@RequestBody MeetingRecordParam meetingRecord){
        MeetingRecordVO meetingRecordResult = meetingService.getMeetingRecord(meetingRecord);
        return this.createResultDataVO(meetingRecordResult, GlobalConstant.SUCCEED, "");
    }

    @ApiOperation(value = "创建会议")
    @PostMapping("/add")
    public ResultDataVO createMeeting(@RequestBody MeetingRecordVO meetingRecord) {
        MeetingRecordVO meetingRecordResult = meetingService.addMeetingRecord(meetingRecord);
        return this.createResultDataVO(meetingRecordResult, Boolean.TRUE);
    }

    @ApiOperation(value = "加入会议")
    @PostMapping("/join")
    public ResultDataVO joinMeeting(String meetingCode, String password) {
        MemberDto memberDto = meetingService.joinMeetingRecord(meetingCode, password);
        return this.createResultDataVO(memberDto, Boolean.TRUE);
    }

    @ApiOperation(value = "结束会议")
    @PostMapping("/end")
    public ResultBasicVO endMeeting(String meetingUUID) {
        meetingService.endMeetingRecord(meetingUUID);
        return this.createResultBasicVO(Boolean.TRUE);
    }
}